home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / atre27.exe / ATREE_27 / LFWIN / BISON.SIM < prev    next >
Text File  |  1992-08-01  |  16KB  |  593 lines

  1. /* -*-C-*-  Note some compilers choke on comments on `#line' lines.  */
  2. #line 3 "bison.sim"
  3.  
  4. /* modification made by MONROE THOMAS 07/18/91 after call to YYLEX to 
  5.    check for negative return value YYEXIT.  Needed for Windows version 
  6.    of parser where exit() calls are not desireable.  Instead, 
  7.    yyparse() will return YYABORT to its caller if yylex() returns 
  8.    YYEXIT.  Users should use return(1) calls in their action file that 
  9.    becomes part of yyparse() instead of exit(1) */
  10.  
  11. /* Skeleton output parser for bison,
  12.    Copyright (C) 1984, 1989, 1990 Bob Corbett and Richard Stallman
  13.  
  14.    This program is free software; you can redistribute it and/or modify
  15.    it under the terms of the GNU General Public License as published by
  16.    the Free Software Foundation; either version 1, or (at your option)
  17.    any later version.
  18.  
  19.    This program is distributed in the hope that it will be useful,
  20.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  21.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  22.    GNU General Public License for more details.
  23.  
  24.    You should have received a copy of the GNU General Public License
  25.    along with this program; if not, write to the Free Software
  26.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  27.  
  28.  
  29. #ifdef __GNUC__
  30. #define alloca __builtin_alloca
  31. #else /* Not GNU C.  */
  32. #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__)
  33. #include <alloca.h>
  34. #endif /* Sparc.  */
  35. #endif /* Not GNU C.  */
  36.  
  37. /* This is the parser code that is written into each bison parser
  38.   when the %semantic_parser declaration is not specified in the grammar.
  39.   It was written by Richard Stallman by simplifying the hairy parser
  40.   used when %semantic_parser is specified.  */
  41.  
  42. /* Note: there must be only one dollar sign in this file.
  43.    It is replaced by the list of actions, each action
  44.    as one case of the switch.  */
  45.  
  46. #define yyerrok         (yyerrstatus = 0)
  47. #define yyclearin       (yychar = YYEMPTY)
  48. #define YYEMPTY         -2
  49.  
  50. /* next define added by M. THOMAS 07/18/91 */
  51.  
  52. #define YYEXIT          -3
  53.  
  54. #define YYEOF           0
  55. #define YYACCEPT        return(0)
  56. #define YYABORT         return(1)
  57. #define YYERROR         goto yyerrlab1
  58. /* Like YYERROR except do call yyerror.
  59.    This remains here temporarily to ease the
  60.    transition to the new meaning of YYERROR, for GCC.
  61.    Once GCC version 2 has supplanted version 1, this can go.  */
  62. #define YYFAIL          goto yyerrlab
  63. #define YYRECOVERING()  (!!yyerrstatus)
  64. #define YYBACKUP(token, value) \
  65. do                                                              \
  66.   if (yychar == YYEMPTY && yylen == 1)                          \
  67.     { yychar = (token), yylval = (value);                       \
  68.       yychar1 = YYTRANSLATE (yychar);                           \
  69.       YYPOPSTACK;                                               \
  70.       goto yybackup;                                            \
  71.     }                                                           \
  72.   else                                                          \
  73.     { yyerror ("syntax error: cannot back up"); YYERROR; }      \
  74. while (0)
  75.  
  76. #define YYTERROR        1
  77. #define YYERRCODE       256
  78.  
  79. #ifndef YYIMPURE
  80. #define YYLEX           yylex()
  81. #endif
  82.  
  83. #ifndef YYPURE
  84. #define YYLEX           yylex(&yylval, &yylloc)
  85. #endif
  86.  
  87. /* If nonreentrant, generate the variables here */
  88.  
  89. #ifndef YYIMPURE
  90.  
  91. int     yychar;                 /*  the lookahead symbol                */
  92. YYSTYPE yylval;                 /*  the semantic value of the           */
  93.                 /*  lookahead symbol                    */
  94.  
  95. #ifdef YYLSP_NEEDED
  96. YYLTYPE yylloc;                 /*  location data for the lookahead     */
  97.                 /*  symbol                              */
  98. #endif
  99.  
  100. int yynerrs;                    /*  number of parse errors so far       */
  101. #endif  /* YYIMPURE */
  102.  
  103. #if YYDEBUG != 0
  104. int yydebug;                    /*  nonzero means print parse trace     */
  105. /* Since this is uninitialized, it does not stop multiple parsers
  106.    from coexisting.  */
  107. #endif
  108.  
  109. /*  YYINITDEPTH indicates the initial size of the parser's stacks       */
  110.  
  111. #ifndef YYINITDEPTH
  112. #define YYINITDEPTH 200
  113. #endif
  114.  
  115. /*  YYMAXDEPTH is the maximum size the stacks can grow to
  116.     (effective only if the built-in stack extension method is used).  */
  117.  
  118. #if YYMAXDEPTH == 0
  119. #undef YYMAXDEPTH
  120. #endif
  121.  
  122. #ifndef YYMAXDEPTH
  123. #define YYMAXDEPTH 10000
  124. #endif
  125.  
  126. /* This is the most reliable way to avoid incompatibilities
  127.    in available built-in functions on various systems.  */
  128. static void
  129. __yy_bcopy (from, to, count)
  130.      char *from;
  131.      char *to;
  132.      int count;
  133. {
  134.   register char *f = from;
  135.   register char *t = to;
  136.   register int i = count;
  137.  
  138.   while (i-- > 0)
  139.     *t++ = *f++;
  140. }
  141.  
  142. #line 143 "bison.sim"
  143. int
  144. yyparse()
  145. {
  146.   register int yystate;
  147.   register int yyn;
  148.   register short *yyssp;
  149.   register YYSTYPE *yyvsp;
  150.   int yyerrstatus;      /*  number of tokens to shift before error messages enabled */
  151.   int yychar1;          /*  lookahead token as an internal (translated) token number */
  152.  
  153.   short yyssa[YYINITDEPTH];     /*  the state stack                     */
  154.   YYSTYPE yyvsa[YYINITDEPTH];   /*  the semantic value stack            */
  155.  
  156.   short *yyss = yyssa;          /*  refer to the stacks thru separate pointers */
  157.   YYSTYPE *yyvs = yyvsa;        /*  to allow yyoverflow to reallocate them elsewhere */
  158.  
  159. #ifdef YYLSP_NEEDED
  160.   YYLTYPE *yyls = yylsa;
  161.   YYLTYPE *yylsp;
  162.   YYLTYPE yylsa[YYINITDEPTH];   /*  the location stack                  */
  163.  
  164. #define YYPOPSTACK   (yyvsp--, yysp--, yylsp--)
  165. #else
  166. #define YYPOPSTACK   (yyvsp--, yysp--)
  167. #endif
  168.  
  169.   int yystacksize = YYINITDEPTH;
  170.  
  171. #ifndef YYPURE
  172.   int yychar;
  173.   YYSTYPE yylval;
  174.   int yynerrs;
  175. #ifdef YYLSP_NEEDED
  176.   YYLTYPE yylloc;
  177. #endif
  178. #endif
  179.  
  180.   YYSTYPE yyval;                /*  the variable used to return         */
  181.                 /*  semantic values from the action     */
  182.                 /*  routines                            */
  183.  
  184.   int yylen;
  185.  
  186. #if YYDEBUG != 0
  187.   if (yydebug)
  188.     fprintf(stderr, "Starting parse\n");
  189. #endif
  190.  
  191.   yystate = 0;
  192.   yyerrstatus = 0;
  193.   yynerrs = 0;
  194.   yychar = YYEMPTY;             /* Cause a token to be read.  */
  195.  
  196.   /* Initialize stack pointers.
  197.      Waste one element of value and location stack
  198.      so that they stay on the same level as the state stack.  */
  199.  
  200.   yyssp = yyss - 1;
  201.   yyvsp = yyvs;
  202. #ifdef YYLSP_NEEDED
  203.   yylsp = yyls;
  204. #endif
  205.  
  206. /* Push a new state, which is found in  yystate  .  */
  207. /* In all cases, when you get here, the value and location stacks
  208.    have just been pushed. so pushing a state here evens the stacks.  */
  209. yynewstate:
  210.  
  211.   *++yyssp = yystate;
  212.  
  213.   if (yyssp >= yyss + yystacksize - 1)
  214.     {
  215.       /* Give user a chance to reallocate the stack */
  216.       /* Use copies of these so that the &'s don't force the real ones into memory. */
  217.       YYSTYPE *yyvs1 = yyvs;
  218.       short *yyss1 = yyss;
  219. #ifdef YYLSP_NEEDED
  220.       YYLTYPE *yyls1 = yyls;
  221. #endif
  222.  
  223.       /* Get the current used size of the three stacks, in elements.  */
  224.       int size = yyssp - yyss + 1;
  225.  
  226. #ifdef yyoverflow
  227.       /* Each stack pointer address is followed by the size of
  228.      the data in use in that stack, in bytes.  */
  229.       yyoverflow("parser stack overflow",
  230.          &yyss1, size * sizeof (*yyssp),
  231.          &yyvs1, size * sizeof (*yyvsp),
  232. #ifdef YYLSP_NEEDED
  233.          &yyls1, size * sizeof (*yylsp),
  234. #endif
  235.          &yystacksize);
  236.  
  237.       yyss = yyss1; yyvs = yyvs1;
  238. #ifdef YYLSP_NEEDED
  239.       yyls = yyls1;
  240. #endif
  241. #else /* no yyoverflow */
  242.       /* Extend the stack our own way.  */
  243.       if (yystacksize >= YYMAXDEPTH)
  244.     {
  245.       yyerror("parser stack overflow");
  246.       return 2;
  247.     }
  248.       yystacksize *= 2;
  249.       if (yystacksize > YYMAXDEPTH)
  250.     yystacksize = YYMAXDEPTH;
  251.       yyss = (short *) alloca (yystacksize * sizeof (*yyssp));
  252.       __yy_bcopy ((char *)yyss1, (char *)yyss, size * sizeof (*yyssp));
  253.       yyvs = (YYSTYPE *) alloca (yystacksize * sizeof (*yyvsp));
  254.       __yy_bcopy ((char *)yyvs1, (char *)yyvs, size * sizeof (*yyvsp));
  255. #ifdef YYLSP_NEEDED
  256.       yyls = (YYLTYPE *) alloca (yystacksize * sizeof (*yylsp));
  257.       __yy_bcopy ((char *)yyls1, (char *)yyls, size * sizeof (*yylsp));
  258. #endif
  259. #endif /* no yyoverflow */
  260.  
  261.       yyssp = yyss + size - 1;
  262.       yyvsp = yyvs + size - 1;
  263. #ifdef YYLSP_NEEDED
  264.       yylsp = yyls + size - 1;
  265. #endif
  266.  
  267. #if YYDEBUG != 0
  268.       if (yydebug)
  269.     fprintf(stderr, "Stack size increased to %d\n", yystacksize);
  270. #endif
  271.  
  272.       if (yyssp >= yyss + yystacksize - 1)
  273.     YYABORT;
  274.     }
  275.  
  276. #if YYDEBUG != 0
  277.   if (yydebug)
  278.     fprintf(stderr, "Entering state %d\n", yystate);
  279. #endif
  280.  
  281.  yybackup:
  282.  
  283. /* Do appropriate processing given the current state.  */
  284. /* Read a lookahead token if we need one and don't already have one.  */
  285. /* yyresume: */
  286.  
  287.   /* First try to decide what to do without reference to lookahead token.  */
  288.  
  289.   yyn = yypact[yystate];
  290.   if (yyn == YYFLAG)
  291.     goto yydefault;
  292.  
  293.   /* Not known => get a lookahead token if don't already have one.  */
  294.  
  295.   /* yychar is either YYEMPTY or YYEOF
  296.      or a valid token in external form.  */
  297.  
  298.   if (yychar == YYEMPTY)
  299.     {
  300. #if YYDEBUG != 0
  301.       if (yydebug)
  302.     fprintf(stderr, "Reading a token: ");
  303. #endif
  304.       yychar = YYLEX;
  305.  
  306.   /* next test added by M. THOMAS. 07/18/91 */
  307.  
  308.       if (yychar == YYEXIT) YYABORT;
  309.     }
  310.  
  311.   /* Convert token to internal form (in yychar1) for indexing tables with */
  312.  
  313.   if (yychar <= 0)              /* This means end of input. */
  314.     {
  315.       yychar1 = 0;
  316.       yychar = YYEOF;           /* Don't call YYLEX any more */
  317.  
  318. #if YYDEBUG != 0
  319.       if (yydebug)
  320.     fprintf(stderr, "Now at end of input.\n");
  321. #endif
  322.     }
  323.   else
  324.     {
  325.       yychar1 = YYTRANSLATE(yychar);
  326.  
  327. #if YYDEBUG != 0
  328.       if (yydebug)
  329.     fprintf(stderr, "Next token is %d (%s)\n", yychar, yytname[yychar1]);
  330. #endif
  331.     }
  332.  
  333.   yyn += yychar1;
  334.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
  335.     goto yydefault;
  336.  
  337.   yyn = yytable[yyn];
  338.  
  339.   /* yyn is what to do for this token type in this state.
  340.      Negative => reduce, -yyn is rule number.
  341.      Positive => shift, yyn is new state.
  342.        New state is final state => don't bother to shift,
  343.        just return success.
  344.      0, or most negative number => error.  */
  345.  
  346.   if (yyn < 0)
  347.     {
  348.       if (yyn == YYFLAG)
  349.     goto yyerrlab;
  350.       yyn = -yyn;
  351.       goto yyreduce;
  352.     }
  353.   else if (yyn == 0)
  354.     goto yyerrlab;
  355.  
  356.   if (yyn == YYFINAL)
  357.     YYACCEPT;
  358.  
  359.   /* Shift the lookahead token.  */
  360.  
  361. #if YYDEBUG != 0
  362.   if (yydebug)
  363.     fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
  364. #endif
  365.  
  366.   /* Discard the token being shifted unless it is eof.  */
  367.   if (yychar != YYEOF)
  368.     yychar = YYEMPTY;
  369.  
  370.   *++yyvsp = yylval;
  371. #ifdef YYLSP_NEEDED
  372.   *++yylsp = yylloc;
  373. #endif
  374.  
  375.   /* count tokens shifted since error; after three, turn off error status.  */
  376.   if (yyerrstatus) yyerrstatus--;
  377.  
  378.   yystate = yyn;
  379.   goto yynewstate;
  380.  
  381. /* Do the default action for the current state.  */
  382. yydefault:
  383.  
  384.   yyn = yydefact[yystate];
  385.   if (yyn == 0)
  386.     goto yyerrlab;
  387.  
  388. /* Do a reduction.  yyn is the number of a rule to reduce with.  */
  389. yyreduce:
  390.   yylen = yyr2[yyn];
  391.   yyval = yyvsp[1-yylen]; /* implement default value of the action */
  392.  
  393. #if YYDEBUG != 0
  394.   if (yydebug)
  395.     {
  396.       if (yylen == 1)
  397.     fprintf (stderr, "Reducing 1 value via rule %d (line %d), ",
  398.          yyn, yyrline[yyn]);
  399.       else
  400.     fprintf (stderr, "Reducing %d values via rule %d (line %d), ",
  401.          yylen, yyn, yyrline[yyn]);
  402.     }
  403. #endif
  404.  
  405. $   /* the action file gets copied in in place of this dollarsign */
  406. #line 378 "bison.sim"
  407.  
  408.   yyvsp -= yylen;
  409.   yyssp -= yylen;
  410. #ifdef YYLSP_NEEDED
  411.   yylsp -= yylen;
  412. #endif
  413.  
  414. #if YYDEBUG != 0
  415.   if (yydebug)
  416.     {
  417.       short *ssp1 = yyss - 1;
  418.       fprintf (stderr, "state stack now");
  419.       while (ssp1 != yyssp)
  420.     fprintf (stderr, " %d", *++ssp1);
  421.       fprintf (stderr, "\n");
  422.     }
  423. #endif
  424.  
  425.   *++yyvsp = yyval;
  426.  
  427. #ifdef YYLSP_NEEDED
  428.   yylsp++;
  429.   if (yylen == 0)
  430.     {
  431.       yylsp->first_line = yylloc.first_line;
  432.       yylsp->first_column = yylloc.first_column;
  433.       yylsp->last_line = (yylsp-1)->last_line;
  434.       yylsp->last_column = (yylsp-1)->last_column;
  435.       yylsp->text = 0;
  436.     }
  437.   else
  438.     {
  439.       yylsp->last_line = (yylsp+yylen-1)->last_line;
  440.       yylsp->last_column = (yylsp+yylen-1)->last_column;
  441.     }
  442. #endif
  443.  
  444.   /* Now "shift" the result of the reduction.
  445.      Determine what state that goes to,
  446.      based on the state we popped back to
  447.      and the rule number reduced by.  */
  448.  
  449.   yyn = yyr1[yyn];
  450.  
  451.   yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
  452.   if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
  453.     yystate = yytable[yystate];
  454.   else
  455.     yystate = yydefgoto[yyn - YYNTBASE];
  456.  
  457.   goto yynewstate;
  458.  
  459. yyerrlab:   /* here on detecting error */
  460.  
  461.   if (! yyerrstatus)
  462.     /* If not already recovering from an error, report this error.  */
  463.     {
  464.       ++yynerrs;
  465.  
  466. #ifdef YYERROR_VERBOSE
  467.       yyn = yypact[yystate];
  468.  
  469.       if (yyn > YYFLAG && yyn < YYLAST)
  470.     {
  471.       int size = 0;
  472.       char *msg;
  473.       int x, count;
  474.  
  475.       count = 0;
  476.       for (x = 0; x < (sizeof(yytname) / sizeof(char *)); x++)
  477.         if (yycheck[x + yyn] == x)
  478.           size += strlen(yytname[x]) + 15, count++;
  479.       msg = (char *) xmalloc(size + 15);
  480.       strcpy(msg, "parse error");
  481.  
  482.       if (count < 5)
  483.         {
  484.           count = 0;
  485.           for (x = 0; x < (sizeof(yytname) / sizeof(char *)); x++)
  486.         if (yycheck[x + yyn] == x)
  487.           {
  488.             strcat(msg, count == 0 ? ", expecting `" : " or `");
  489.             strcat(msg, yytname[x]);
  490.             strcat(msg, "'");
  491.             count++;
  492.           }
  493.         }
  494.       yyerror(msg);
  495.       free(msg);
  496.     }
  497.       else
  498. #endif /* YYERROR_VERBOSE */
  499.     yyerror("parse error");
  500.     }
  501.  
  502. yyerrlab1:   /* here on error raised explicitly by an action */
  503.  
  504.   if (yyerrstatus == 3)
  505.     {
  506.       /* if just tried and failed to reuse lookahead token after an error, discard it.  */
  507.  
  508.       /* return failure if at end of input */
  509.       if (yychar == YYEOF)
  510.     YYABORT;
  511.  
  512. #if YYDEBUG != 0
  513.       if (yydebug)
  514.     fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
  515. #endif
  516.  
  517.       yychar = YYEMPTY;
  518.     }
  519.  
  520.   /* Else will try to reuse lookahead token
  521.      after shifting the error token.  */
  522.  
  523.   yyerrstatus = 3;              /* Each real token shifted decrements this */
  524.  
  525.   goto yyerrhandle;
  526.  
  527. yyerrdefault:  /* current state does not do anything special for the error token. */
  528.  
  529. #if 0
  530.   /* This is wrong; only states that explicitly want error tokens
  531.      should shift them.  */
  532.   yyn = yydefact[yystate];  /* If its default is to accept any token, ok.  Otherwise pop it.*/
  533.   if (yyn) goto yydefault;
  534. #endif
  535.  
  536. yyerrpop:   /* pop the current state because it cannot handle the error token */
  537.  
  538.   if (yyssp == yyss) YYABORT;
  539.   yyvsp--;
  540.   yystate = *--yyssp;
  541. #ifdef YYLSP_NEEDED
  542.   yylsp--;
  543. #endif
  544.  
  545. #if YYDEBUG != 0
  546.   if (yydebug)
  547.     {
  548.       short *ssp1 = yyss - 1;
  549.       fprintf (stderr, "Error: state stack now");
  550.       while (ssp1 != yyssp)
  551.     fprintf (stderr, " %d", *++ssp1);
  552.       fprintf (stderr, "\n");
  553.     }
  554. #endif
  555.  
  556. yyerrhandle:
  557.  
  558.   yyn = yypact[yystate];
  559.   if (yyn == YYFLAG)
  560.     goto yyerrdefault;
  561.  
  562.   yyn += YYTERROR;
  563.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
  564.     goto yyerrdefault;
  565.  
  566.   yyn = yytable[yyn];
  567.   if (yyn < 0)
  568.     {
  569.       if (yyn == YYFLAG)
  570.     goto yyerrpop;
  571.       yyn = -yyn;
  572.       goto yyreduce;
  573.     }
  574.   else if (yyn == 0)
  575.     goto yyerrpop;
  576.  
  577.   if (yyn == YYFINAL)
  578.     YYACCEPT;
  579.  
  580. #if YYDEBUG != 0
  581.   if (yydebug)
  582.     fprintf(stderr, "Shifting error token, ");
  583. #endif
  584.  
  585.   *++yyvsp = yylval;
  586. #ifdef YYLSP_NEEDED
  587.   *++yylsp = yylloc;
  588. #endif
  589.  
  590.   yystate = yyn;
  591.   goto yynewstate;
  592. }
  593.